<template>
	<div>
		<el-table :key="tableKey" :data="data" v-loading="listLoading">
			<div v-for="(item,index)  in checkedTableColumn" :key="index">
				<el-table-column :label="item.label" v-if="item.ispass" :min-width='checkTableWidth(index) '>
					<template slot-scope="{ row }">
						<div v-if="item.label=='巡检结果'">
							<span v-if="row[item.value]=== '1'">正常</span>
							<span v-if="row[item.value]=== '2'">异常</span>
							<span v-if="row[item.value]=== '3'">跳过</span>
						</div>
						<div v-else-if="item.label=='状态变更'">
							<span v-if="row.lastCheckResult === '2'">维修中</span>
							<span v-else>正常</span>
							<span>→</span>
							<span v-if="row.facilityStatus === '2'">维修中</span>
							<span v-else>正常</span>
						</div>

						<div v-else> {{ row[item.value] }} </div>
					</template>
				</el-table-column>
			</div>
		</el-table>
	</div>
</template>

<script>
	export default {
		name: "hisTable",
		props: {
			data: {
				type: Array,
				default: [],
			},
			tableColumn: {
				type: Array,
				default: [],
			},
			tableChecked: {
				type: Array,
				default: [],
			},
			checkedTableColumn: {
				type: Array,
				default: [],
			},
			tasktype: {
				type: String,
				default: ''
			},
			listLoading: {
				type: Boolean,
				default: false,
			},
			taskFlag: {
				type: String,
				default: '',
			}
		},
		components: {

		},
		data() {
			return {
				inspectionFlag: false,
				inspectId: '',
				taskShow: true,
				tableKey: 0,
				defaultFormThead: [{
						value: 'checkResult',
						label: '巡检结果',
						ispass: true,
						width: '80'
					},
					{
						value: 'deptName',
						label: '所属单位',
						ispass: true,
						width: '100'
					},
					{
						value: '',
						label: '状态变更',
						ispass: true,
						width: '100'
					},
					{
						value: 'facilityNo',
						label: '设施编号',
						ispass: true,
						width: '100'
					},
					{
						value: 'facilityName',
						label: '设施类型',
						ispass: true,
						width: '100'
					},
					{
						value: 'taskNo',
						label: '巡检任务编号',
						ispass: this.taskFlag != 'task',
						width: '110'
					},
					{
						value: 'buildingName',
						label: '所属建筑',
						ispass: true,
						width: '100'
					},
					{
						value: 'facilityFloor',
						label: '楼层',
						ispass: true,
						width: '60'
					},
					{
						value: 'locationDesc',
						label: '位置描述',
						ispass: true,
						width: '80'
					},
					{
						value: 'realName',
						label: '巡检人',
						ispass: true,
						width: '70'
					},
					{
						value: 'phone',
						label: '联系电话',
						ispass: this.taskFlag != 'task',
						width: '100'
					},
					{
						value: 'creatTime',
						label: '巡检时间',
						ispass: true,
						width: '100'
					},
					{
						value: 'planFinishTime',
						label: '计划完成时间',
						ispass: this.taskFlag != 'task',
						width: '110'
					},

				],
				checked: ['巡检结果', '所属单位', '状态变更', '设施编号', '设施类型', '巡检任务编号', '所属建筑', '楼层', '位置描述', '巡检人', '联系电话', '巡检时间',
					'计划完成时间',
				],
			};
		},
		created() {
			this.getcheckedTableColumn()
		},
		methods: {
			// 列表自定义
			getcheckedTableColumn() {

				this.$emit('getcheckedtable', this.checked, this.tableKey, this.defaultFormThead)
			},
			// 自定义宽度
			checkTableWidth(index) {
				return this.checkedTableColumn[index].width
			},
			detail(row) {
				//如果从巡检任务出跳过来
				if (this.taskFlag == 'task') {
					//如果数据已经巡检
					if (row.historyId) {
						this.inspectId = row.historyId
						this.inspectionFlag = true
					} else {
						this.$notify({
							title: '提示',
							message: '该设施暂未巡检，请巡检后查看明细',
							type: 'warning',
							customClass: 'warning'
						});
					}
				} else {
					this.inspectId = row.id
					this.inspectionFlag = true
				}


			},
		},
	};
</script>

<style lang="scss"></style>